<?php

class TagTable extends Doctrine_Table {

  /**
   * @return TagTable
   */
  public static function getInstance()
  {
    return Doctrine::getTable('Tag');
  }

  /**
   * Retrieves all the tags with the number of times they are attached to
   * a bookmark (weight).
   *
   * @return array an array of Tag
   */
  public function retrieveTagsWithWeight()
  {
    $q = $this->createQuery('bt')
            ->select('bt.*, count(bt.id)')
            ->groupBy('bt.name')
            ->orderBy('bt.name ASC');

    return $q->fetchArray();
  }

  public function deleteById($id)
  {
    $query = $this->createQuery()->delete()->where('id = ?', $id);

    return $query->execute();
  }
}